package com.gxa.controller;

import com.gxa.common.base.LayuiResultJson;
import com.gxa.common.base.R;
import com.gxa.domain.dto.SysRoleSaveDTO;
import com.gxa.domain.entity.SysRole;
import com.gxa.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sys_role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    // 查询所有角色信息-带分页
    @RequestMapping(value = "/findSysRoleAll",method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson findSysRoleAll(Integer page, Integer limit){
        return sysRoleService.findSysRoleAll(page,limit);
    }

    // 根据角色ID删除角色信息
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public R delSysRoleByRoleId(Integer roleId){
        return sysRoleService.delRoleByRoleId(roleId);
    }

    // 添加角色信息
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public R saveSysRole(@RequestBody SysRoleSaveDTO sysRoleSaveDTO){
        return sysRoleService.addSysRole(sysRoleSaveDTO);
    }

    // 修改角色信息
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public R updateSysRole(@RequestBody SysRole sysRole){
        return sysRoleService.updateSysRole(sysRole);
    }


    // 修改角色信息
    @RequestMapping(value = "/search",method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson search(String roleName,Integer page,Integer limit){
        return sysRoleService.search(roleName,page,limit);
    }
}
